package cn.com.dhcc.turbo.service.exch.filedata;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.dhcc.app.core.dao.CrudDao;
import cn.com.dhcc.app.core.exception.DaoException;
import cn.com.dhcc.app.core.exception.NiceException;
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.handler.modulehandler.WhereCondition;
import cn.com.dhcc.app.core.service.AbstractCrudService;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.pub.core.consts.AppConst;
import cn.com.dhcc.turbo.dao.exch.CrossNetTmpFileDataDao;
import cn.com.dhcc.turbo.entity.exch.CrossNetTmpFileData;

@Service
public class CrossNetTmpFileDataService extends AbstractCrudService<CrossNetTmpFileData> {
    @SuppressWarnings("deprecation")
	private static Logger logger = Log.getExistLogger(LOGTYPE.R);

    @Autowired
    private CrossNetTmpFileDataDao dao;

    @Override
    public CrudDao<CrossNetTmpFileData> getCrudDao() {
        return dao;
    }
    /**
     * 中转节点需要刻盘的
     * @return
     * @throws ServiceException
     */
	public List<CrossNetTmpFileData> getCarvedDiscs() throws ServiceException {
		WhereCondition parameter = new WhereCondition();
		parameter.where().eq("SEND_STATUS", AppConst.SendStatus.FAIL.value())
		.and().eq("CROSS_NET", AppConst.CrossNetType.OUT_INNER_NETWORK.value())
		.and().eq("THROUGH_GAP", "2");
		return this.list(parameter);
	}
    /**
     * 查询还未发送到网闸节点的数据
     * @return
     * @throws ServiceException
     */
	public List<CrossNetTmpFileData> getLocaleGapUnsentList() throws ServiceException {
		WhereCondition parameter = new WhereCondition();
		parameter.where().eq("SEND_STATUS", AppConst.SendStatus.OUTER_ENTREPOT_READY.value());
		return this.list(parameter);
	}

	/**
	 * 获取内网网闸节点待发送的数据
	 * @return
	 * @throws NiceException
	 * @throws ServiceException
	 */
	public List<CrossNetTmpFileData> getInnerEntrepotUnsentList() throws NiceException,ServiceException {
		WhereCondition parameter = new WhereCondition();
		parameter.where().eq("SEND_STATUS", AppConst.SendStatus.INNER_ENTREPOT_READY.value())
			.and().eq("CROSS_NET", AppConst.CrossNetType.OUT_INNER_NETWORK.value());
		return this.list(parameter);
	}
	
	public int updateSendStatus(List<CrossNetTmpFileData> dataList,
			String status) throws NiceException {
		   try {
	            return dao.updateSendStatus(dataList, status);
	        } catch (DaoException e) {
	            logger.error(e);
	            throw new NiceException(e);
	        }
		
	}
	

	/**
	 * 获取发送节点列表
	 * 
	 * @return
	 */
	public List<Map<String, Object>> getSendNodeList() throws NiceException {
		try {
			return dao.getSendNodeList();
		} catch (DaoException e) {
			logger.error(e);
			throw new NiceException(e);
		}
	}

	/**
	 * 获取接收节点列表
	 * 
	 * @return
	 */
	public List<Map<String, Object>> getRecvNodeList() throws NiceException {
		try {
			return dao.getRecvNodeList();
		} catch (DaoException e) {
			logger.error(e);
			throw new NiceException(e);
		}
	}

}
